<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Mretaurantcategories extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * 
     * @void Country
     * 
     */
    
    public function getRetaurantCategoriesDB($number,$offset)
    {
        $limit = $offset ? intval($offset) : '0';
        
        $sql = "SELECT * FROM restaurantcategories WHERE 1=1 ";
        $key = $this->getParamString('keyword');
        if(!in_array($key, array(null, '', '0')))
        {
            $sql .= " AND (title like '%%".$key."%%' OR ";
            $sql .= " title_ascii like '%%".$key."%%') ";
        }
        $sql .= "ORDER BY id DESC";
        
        $xdata = " LIMIT ".$limit.",".$number." ";
        $xs = $this->db->query($sql.$xdata)->result_object();
        $count = $this->db->query($sql)->num_rows();
        return array('data' => $xs, 'count' => $count);   
    }
    
    public function addRetaurantCategoriesDb($admin_id)
    {
        $title = $this->getParamString('title');
        $title_ascii = $this->get_ascii($title);
        
        $arr = array(
                'title'         => $title,
                'title_ascii'   => $title_ascii,
                'admin_id'      => $admin_id,
                'created'       => date('Y-m-d H:i:s')
            );
        $this->db->insert('restaurantcategories', $arr);
        return 200;
    }
    public function editRetaurantCategoriesDb($admin_id, $id)
    {
        $title = $this->getParamString('title');
        $title_ascii = $this->get_ascii($title);
        
        $arr = array(
                'title'         => $title,
                'title_ascii'   => $title_ascii,
                'admin_id'      => $admin_id,
                'created'       => date('Y-m-d H:i:s')
            );
        $this->db->update('country', $arr, "id = ".$id);
        return 200;
    }
    
    public function deleteRetaurantCategoriesDB($id)
    {
        $this->db->query("DELETE FROM restaurantcategories WHERE id IN ('" . (is_array($id) ? implode("','", $id) : $id) . "')");
        return 200;
    }
    
    public function getRetaurantCategoriesDetailDB($id)
    {
        return $this->db->query('SELECT * FROM restaurantcategories WHERE id = '.$id)->row_object();
    }
    

    
}
